package com.ruoyi.web.controller.wbgame;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wbgame.domain.WbStuGame;
import com.ruoyi.wbgame.service.IWbStuGameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生参与游戏Controller
 * 
 * @author guguofu
 * @date 2021-04-16
 */
@Controller
@RequestMapping("/wbgame/stuGame")
public class WbStuGameController extends BaseController
{
    private String prefix = "wbgame/stuGame";

    @Autowired
    private IWbStuGameService wbStuGameService;

    @RequiresPermissions("wbgame:stuGame:view")
    @GetMapping()
    public String stuGame()
    {
        return prefix + "/stuGame";
    }

    /**
     * 查询学生参与游戏列表
     */
    @RequiresPermissions("wbgame:stuGame:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WbStuGame wbStuGame)
    {
        startPage();
        List<WbStuGame> list = wbStuGameService.selectWbStuGameList(wbStuGame);
        return getDataTable(list);
    }

    /**
     * 导出学生参与游戏列表
     */
    @RequiresPermissions("wbgame:stuGame:export")
    @Log(title = "学生参与游戏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WbStuGame wbStuGame)
    {
        List<WbStuGame> list = wbStuGameService.selectWbStuGameList(wbStuGame);
        ExcelUtil<WbStuGame> util = new ExcelUtil<WbStuGame>(WbStuGame.class);
        return util.exportExcel(list, "stuGame");
    }

    /**
     * 新增学生参与游戏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生参与游戏
     */
    @RequiresPermissions("wbgame:stuGame:add")
    @Log(title = "学生参与游戏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WbStuGame wbStuGame)
    {
        return toAjax(wbStuGameService.insertWbStuGame(wbStuGame));
    }

    /**
     * 修改学生参与游戏
     */
    @GetMapping("/edit/{studentId}")
    public String edit(@PathVariable("studentId") Long studentId, ModelMap mmap)
    {
        WbStuGame wbStuGame = wbStuGameService.selectWbStuGameById(studentId);
        mmap.put("wbStuGame", wbStuGame);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生参与游戏
     */
    @RequiresPermissions("wbgame:stuGame:edit")
    @Log(title = "学生参与游戏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WbStuGame wbStuGame)
    {
        return toAjax(wbStuGameService.updateWbStuGame(wbStuGame));
    }

    /**
     * 删除学生参与游戏
     */
    @RequiresPermissions("wbgame:stuGame:remove")
    @Log(title = "学生参与游戏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wbStuGameService.deleteWbStuGameByIds(ids));
    }
}
